﻿using System;

namespace ProjectEuler
{
    internal class Problem26
    {
        public void Solve()
        {
            int num, len;
            var res = Do(out num, out len);
            Console.WriteLine("num = {0} len = {1}", num, len);
        }

        int Do(out int num, out int len)
        {
            num = 0;
            len = 0;
            int sequenceLength = 0;

            for (var i = 1000; i > 1; i--)
            {
                if (sequenceLength >= i)
                {
                    break;
                }

                var foundRemainders = new int[i];
                var value = 1;
                var position = 0;

                while (foundRemainders[value] == 0 && value != 0)
                {
                    foundRemainders[value] = position;
                    value *= 10;
                    value %= i;
                    position++;
                }

                if (position - foundRemainders[value] > sequenceLength)
                {
                    sequenceLength = position - foundRemainders[value];

                    num = i;
                    len = sequenceLength;
                }
            }

            return sequenceLength;
        }
    }
}